package com.freewater.springboot.demo.spel.beanref;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AppConfig {

    @Bean
    MyBeanFactory myBean() {
        return new MyBeanFactory();
    }

    public static class MyBean {

        final String name;

        public MyBean(String name) {
            this.name = name;
        }

        public String getName() {
            return this.name;
        }
    }

    public static class MyBeanFactory implements FactoryBean<MyBean> {

        @Override
        public MyBean getObject() {
            return new MyBean("freewater");
        }

        @Override
        public Class<?> getObjectType() {
            return MyBean.class;
        }

        @Override
        public String toString() {
            return "MyBean('freewater') FactoryBean：" + super.toString();
        }
    }
}
